package org.kjtc.controller;

import org.kjtc.entity.Sprint;
import org.kjtc.entity.SprintCommon;
import org.kjtc.entity.UserInfo;
import org.kjtc.service.SprintService;
import org.kjtc.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/4 0004.
 */
@RestController
public class SprintController extends BaseController {

    @Autowired
    private SprintService sprintService;

    @RequestMapping(value = "doGetSprint")
    public JsonResult doGetSprint(String productVersionID) {
        List<Sprint> list = sprintService.getSprint(productVersionID);
        return new JsonResult(list);
    }

    @RequestMapping(value = "doGetMessageBySprintId")
    public JsonResult doGetMessageBySprintId(@RequestParam("sprintID") String sprintID) {
        List<SprintCommon> list = sprintService.getSprintBySprintId(sprintID);
        return new JsonResult(list);
    }

    @RequestMapping(value = "doGetBackLogStateBySprintId")
    public JsonResult doGetBackLogStateBySprintId(@RequestParam("sprintID") String sprintID) {
        List<Map<String, Object>> list = sprintService.getBackLogStateBySprintId(sprintID);
        return new JsonResult(list);
    }

    @RequestMapping(value = "doGetBackLogCountByEveryDay")
    public JsonResult doGetBackLogCountByEveryDay(@RequestParam("sprintID") String sprintID) {
        List<Map<String, Object>> list = sprintService.getBackLogCountByEveryDay(sprintID);
        return new JsonResult(list);
    }

    @RequestMapping(value = "doAddSprint")
    public JsonResult doAddSprint(Sprint sprint) {
        UserInfo userInfo= (UserInfo) this.getSession().getAttribute("userInfo");
        String userID=userInfo.getUserID();
        if(userID != null && userID != ""){
            sprint.setCreateUser(userID);
            sprint.setUpdateUser(userID);
        }
        int num = sprintService.addSprint(sprint);
        return new JsonResult(num);
    }

    @RequestMapping(value = "doGetSprintBySprintID")
    public JsonResult doGetSprintBySprintID(@RequestParam("sprintID") String sprintID) {
        List<Sprint> list = sprintService.getSprintMessageBySprintID(sprintID);
        return new JsonResult(list);
    }

    @RequestMapping(value = "doUpdateSprintBySprintID")
    public JsonResult doUpdateSprintBySprintID(Sprint sprint) {
        UserInfo userInfo= (UserInfo) this.getSession().getAttribute("userInfo");
        String userID=userInfo.getUserID();
        if(userID != null && userID != ""){
            sprint.setUpdateUser(userID);
        }
        int num = sprintService.updateSprintBySprintID(sprint);
        return new JsonResult(num);
    }
    @RequestMapping(value = "doDeleteSprintById")
    public JsonResult doDeleteSprintById(@RequestParam("sprintID") String sprintID) {
        int num = sprintService.deleteSprintById(sprintID);
        return new JsonResult(num);
    }
    @RequestMapping(value = "doGetProductVersionID")
    public JsonResult doGetProductVersionID(@RequestParam("sprintID") String sprintID) {
        List<Sprint> list = sprintService.getSprintMessageBySprintID(sprintID);
        return new JsonResult(list);
    }
    @RequestMapping(value = "doGetTaskState")
    public JsonResult doGetTaskState(@RequestParam("sprintID") String sprintID) {
        List<SprintCommon> list = sprintService.getTaskState(sprintID);
        return new JsonResult(list);
    }
    @RequestMapping(value = "doUpdateCurrentTitle")
    public JsonResult doUpdateCurrentTitle(@RequestParam("sprintID") String sprintID) {
        List<Sprint> list = sprintService.updateCurrentTitle(sprintID);
        return new JsonResult(list);
    }
    @RequestMapping(value = "getProductNameByProductVersionID")
    public JsonResult doGetProductNameByProductVersionID(@RequestParam("ProductVersionID") String ProductVersionID) {
        List<Sprint> list = sprintService.getProductNameByProductVersionID(ProductVersionID);
        return new JsonResult(list);
    }

}
